package com.qf.web.controller;

import com.github.pagehelper.PageInfo;
import com.qf.entity.Member;
import com.qf.entity.Pagination;
import com.qf.entity.Result;
import com.qf.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/member1")
public class MemberController {

    @Autowired
    private MemberService memberService;

    @GetMapping("find")
    public Result findByPage(Pagination pagination){
        PageInfo<Member> pageInfo = memberService.findByPageAndName(pagination);
        return Result.success(pageInfo);
    }


    @PostMapping("add")
    public int  addMember(@RequestBody Member member){
        System.out.println(member);
        int i = memberService.addMember(member);
        System.out.println(i);
        return i;
    }

    @PostMapping("edit")
    public Result edit(@RequestBody Member member){
        int edit = memberService.edit(member);
        if (edit>0){
            return Result.success("修改成功");
        }
        return Result.success("修改失败");
    }

    @PostMapping  ("delete")
    public Result delete(Integer id){
        int delete = memberService.delete(id);
        return Result.success(delete);
    }

    @PostMapping("findById")
    public Result findBYiD(@RequestBody Member member){
        System.out.println(member.getId());
        Member byId = memberService.findById(member.getId());
        return Result.success(byId);
    }
}
